import request from '@/utils/request'
// import {formDataFun} from './public'
function formDataFun(data) {
  const param = new FormData()
  const keys = Object.keys(data)
  keys.forEach((item, index) => {
    param.append(item, data[item])
  })
  return param
}
// 获取菜单
export function getUserMenus() {
  return request({
    url: '/ht-user/user/getUserMenus',
    method: 'post',
    data: {}
  })
}
// 登录
export function login(data) {
  let a=formDataFun(data)
  return request({
    url: '/ht-auth/oauth/token',
    method: 'post',
    data: formDataFun(data)
  })
}
// 登出
export function logout() {
  return request({
    url: '/ht-user/user/logout',
    method: 'get'
  })
}

// 用户修改密码
export function userPasswordEdit(data) {
  return request({
    url: '/ht-user/user/userPasswordEdit',
    method: 'post',
    data: formDataFun(data)
  })
}

// 重置密码
export function userPasswordReset(data) {
  return request({
    url: '/ht-user/user/userPasswordReset',
    method: 'post',
    data: formDataFun(data)
  })
}

// 获取角色列表----------------------------------------------------------
export function getRoleList() {
  return request({
    url: '/ht-user/role/getRoleList',
    method: 'get'
  })
}

// 角色新增
export function saveRole(data) {
  return request({
    url: '/ht-user/role/saveRole',
    method: 'post',
    data: data
  })
}
// 获取角色权限
export function getRolePermissions(data) {
  return request({
    url: '/ht-user/role/getRolePermissions',
    method: 'post',
    data: formDataFun(data)
  })
}
// 角色权限修改
export function rolePermissionEdit(data) {
  return request({
    url: '/ht-user/role/rolePermissionEdit',
    method: 'post',
    data: data
  })
}

// 角色删除
export function delRole(data) {
  return request({
    url: '/ht-user/role/delRole',
    method: 'post',
    data: formDataFun(data)
  })
}

// 获取用户列表------------------------------------------------------------------
export function getUserList(data) {
  return request({
    url: '/ht-user/user/getUserList',
    method: 'post',
    data: data
  })
}

// 获取用户角色
export function getUserRoles(v) {
  return request({
    url: '/ht-user/user/getUserRoles?user_id=' + v,
    method: 'post'
    // data: v
  })
}

// 用户角色编辑
export function userRoleAddEdit(data) {
  return request({
    url: '/ht-user/user/userRoleAddEdit',
    method: 'post',
    data: data
  })
}

// 用户新增修改
export function htuserusersave(data) {
  return request({
    url: '/ht-user/user/save',
    method: 'post',
    data: data
  })
}

// 用户删除
export function delUser(data) {
  return request({
    url: `/ht-user/user/delUser?user_id=${data}`,
    method: 'post'
  })
}
// 权限管理-------------------------------------------------------------------------------
// 获取权限全部菜单
export function getPermissions() {
  return request({
    url: `/ht-user/permission/getPermissions`,
    method: 'get'
  })
}

// 权限菜单新增修改
export function savePermission(data) {
  return request({
    url: `/ht-user/permission/savePermission`,
    method: 'post',
    data
  })
}

// 删除权限菜单节点
export function delPermission(data) {
  return request({
    url: `/ht-user/permission/delPermission`,
    method: 'post',
    data: formDataFun(data)
  })
}
// 部门岗位管理-------------------------------------------------------------------
// 部门列表
export function getDeptList() {
  return request({
    url: `/ht-user/dept/getDeptList`,
    method: 'get'
  })
}
// 部门删除
export function delDept(data) {
  return request({
    url: `/ht-user/dept/delDept?dept_id=${data.dept_id}`,
    method: 'post'
    // data:data
  })
}
// 部门增加修改
export function saveDept(v) {
  return request({
    url: `/ht-user/dept/saveDept`,
    method: 'post',
    data: v
  })
}
// 岗位列表
export function getPostList() {
  return request({
    url: `/ht-user/dept/getPostList`,
    method: 'get'
  })
}
// 岗位删除
export function delPost(v) {
  return request({
    url: `/ht-user/dept/delPost?post_id=${v}`,
    method: 'post'
  })
}
// 岗位新增，修改
export function savePost(v) {
  return request({
    url: `/ht-user/dept/savePost`,
    method: 'post',
    data: v
  })
}
